package com.kaiwukj.android.ufamily.mvp.ui.page.service.gm;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.mcas.utils.RxLifecycleUtils;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.GMAppointmentOrderResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.GMOrderDetailResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.GMOrderResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.service.ServiceContract;

import javax.inject.Inject;


public class GMOrderPresenter extends BasePresenter<ServiceContract.Model, ServiceContract.GMOrderView> {

    @Inject
    public GMOrderPresenter(ServiceContract.Model model, ServiceContract.GMOrderView view) {
        super(model, view);
    }

    public void fetchGMWorkingOrder(int page, int pageSize) {
        mModel.fetchGMOrder(page, pageSize)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<GMOrderResult>>(mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<GMOrderResult> result) {
                        mRootView.onFetchGMOrder(result.getList());
                    }
                });
    }


    public void fetchGMAppointmentOrder(int page, int pageSize) {
        mModel.fetchGMAppointmentOrder(page, pageSize)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<GMAppointmentOrderResult>>(mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<GMAppointmentOrderResult> result) {
                        mRootView.onFetchGMAppointmentOrder(result.getList());
                    }
                });
    }

    public void fetchGMOrderDetail(int orderId) {
        mModel.getGMOrderDetail(orderId)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<GMOrderDetailResult>(mRootView) {
                    @Override
                    public void onSuccess(@NonNull GMOrderDetailResult result) {
                        mRootView.onGetOrderDetail(result);
                    }
                });
    }

}
